////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.core.base.selector
{
	import org.woozoo.xhtml.core.base.Element;
	
	/**
	 * @private
	 * */
	internal class AbstractSelectorOperatorOnly extends AbstractSelectorOperatorNthChild
	{
		protected var _firstType : String;
		protected var _lastType : String;
		
		override protected function _operateElements() : Array {
			if (!_firstType || !_lastType) {
				throw new Error('AbstractSelectorOperatorOnly is an abstract class');
			}
			_type = _firstType;
			var res1 : Array = super._operateElements();
			_type = _lastType;
			var res2 : Array = super._operateElements();
			
			var res : Array = [];
			var len1 : int = res1.length;
			var len2 : int = res2.length;
			for (var i : int = 0; i < len1; i++) {
				var item1 : Element = res1[i];
				for (var j : int = 0; j < len2; j++) {
					var item2 : Element = res2[j];
					if (item1 == item2) {
						res.push(item1);
						break;
					}
				}
			}
			return res;
		}
	}
}